package top.csjss.hospital.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.csjss.hospital.entity.Doctor;
import top.csjss.hospital.entity.DoctorExample;
import top.csjss.hospital.mapper.DoctorMapper;
import top.csjss.hospital.service.DoctorService;
import top.csjss.hospital.vo.DoctorVO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ztf
 * @Date 21:43 2021/10/19
 **/
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public List<Map<String, Object>> findSchedulerByWeek(String week) {
        //调用doctorMapper查询排班信息
        List<String> doctorNameList = doctorMapper.selectDoctorNameBySchedulerAndWeek(week);
        //封装数据
        List<Map<String,Object>> result = new ArrayList<>();
        for (String doctorName : doctorNameList) {
            Map<String,Object> map = new HashMap<>();
            map.put("doctorName",doctorName);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<DoctorVO> selectDoctor(Integer registeredId, Integer departmentId) {
        //封装查询条件
        DoctorExample example = new DoctorExample();
        DoctorExample.Criteria criteria = example.createCriteria();
        criteria.andRegisteredIdEqualTo(registeredId);
        criteria.andDepartmentIdEqualTo(departmentId);
        List<Doctor> doctors = doctorMapper.selectByExample(example);

        //封装返回结果
        List<DoctorVO> data = new ArrayList<>();
        for (Doctor doctor : doctors) {
            DoctorVO vo = new DoctorVO(doctor.getDoctorId(), doctor.getDoctorName());
            data.add(vo);
        }
        return data;
    }
}
